//
// Copyright (C) 2011 Steve Channell steve.channell@cepheis.com
//
// This file is part of Cephei.QL, an open-source library wrapper 
// arround QuantLib http://quantlib.org/
//
// Cephei.QL is open source software: you can redistribute it and/or modify it
// under the terms of the license.  You should have received a
// copy of the license along with this program; if not, please email
// <support@cepheis.com>. The license is also available online at
// <http://cepheis.com/license.htm>.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
// FOR A PARTICULAR PURPOSE.  See the license for more details.
//
// Version 2.101
//#include "stdafx.h"
#include "MakeVanillaSwap.h"
using namespace Cephei::QL::Instruments;
#include <gen/QL/Times/Period.h>
#include <gen/QL/Indexes/IborIndex.h>
#include <gen/QL/Instruments/VanillaSwap.h>
#include <gen/QL/Termstructures/YieldTermStructure.h>
#include <gen/QL/Times/Calendar.h>
#include <gen/QL/Times/DayCounter.h>
using namespace Cephei::QL::Times;
using namespace Cephei::QL::Indexes;
using namespace Cephei::QL::Termstructures;
#undef HANDLE
#undef ABSTRACT
#undef STRUCT
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ fixedRate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart) 
{
	_pSpinlock = new boost::detail::spinlock ();
    CPeriod^ _CswapTenor;
    CIborIndex^ _CiborIndex;
    CPeriod^ _CforwardStart;
    try
    {
#ifdef HANDLE
        _phMakeVanillaSwap = NULL;
#endif
        _CswapTenor = safe_cast<CPeriod^> (swapTenor);
        _CswapTenor->Lock();
        QuantLib::Period& _swapTenor = static_cast<QuantLib::Period&> (_CswapTenor->GetReference ()); 
        _CiborIndex = safe_cast<CIborIndex^> (iborIndex);
        _CiborIndex->Lock();
        boost::shared_ptr<QuantLib::IborIndex>& _iborIndex = static_cast<boost::shared_ptr<QuantLib::IborIndex>&> (_CiborIndex->GetShared ()); 
        QuantLib::Rate _fixedRate = 
            (Microsoft::FSharp::Core::FSharpOption<Double>::IsSome::get (fixedRate) ? (QuantLib::Rate)ValueHelper::Convert (fixedRate->Value) : Null<QuantLib::Rate>()); //4
        if (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart))
        {
            _CforwardStart = safe_cast<CPeriod^> (forwardStart->Value);
            _CforwardStart->Lock();
        }
        QuantLib::Period& _forwardStart = 
            (Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>::IsSome::get (forwardStart) ? static_cast<QuantLib::Period&> (_CforwardStart->GetReference ()) : 0*Days); //1
        _ppMakeVanillaSwap = new boost::shared_ptr<QuantLib::MakeVanillaSwap> (new QuantLib::MakeVanillaSwap ( _swapTenor,  _iborIndex,  _fixedRate,  _forwardStart ));
        
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CswapTenor != nullptr) _CswapTenor->Unlock();
        if (_CiborIndex != nullptr) _CiborIndex->Unlock();
        if (_CforwardStart != nullptr) _CforwardStart->Unlock();
    }
}
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (boost::shared_ptr<QuantLib::MakeVanillaSwap>& childNative, Object^ owner) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeVanillaSwap = NULL;
#endif
	_ppMakeVanillaSwap = &childNative;
    
}
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (QuantLib::MakeVanillaSwap& childNative, Object^ owner) 
{
#ifdef HANDLE
	_phMakeVanillaSwap = NULL;
#endif
	_ppMakeVanillaSwap = new boost::shared_ptr<QuantLib::MakeVanillaSwap> (&childNative);
    
    _MakeVanillaSwapOwner = owner;
    
}

Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (CMakeVanillaSwap^ copy) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeVanillaSwap = NULL;
#endif
	if (copy->HasNative() != NULL)
    {
		_ppMakeVanillaSwap = new boost::shared_ptr<QuantLib::MakeVanillaSwap> (copy->GetShared());
        
    }
}
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (System::Type^ t) 
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeVanillaSwap = NULL;
#endif
	if (!t->IsSubclassOf(CMakeVanillaSwap::typeid))
		throw gcnew Exception ("Invalid base-case init");
}
#ifdef HANDLE
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (QuantLib::Handle<QuantLib::MakeVanillaSwap>& childNative, Object^ owner)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMakeVanillaSwap = &childNative;
	_ppMakeVanillaSwap = &static_cast<boost::shared_ptr<QuantLib::MakeVanillaSwap>>(childNative.currentLink());
    
    _MakeVanillaSwapOwner = owner;
}
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (QuantLib::Handle<QuantLib::MakeVanillaSwap> childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
	_phMakeVanillaSwap = &childNative;
	_ppMakeVanillaSwap = &static_cast<boost::shared_ptr<QuantLib::MakeVanillaSwap>>(childNative.currentLink());
    
}
#endif
#ifdef STRUCT
Cephei::QL::Instruments::CMakeVanillaSwap::CMakeVanillaSwap (QuantLib::MakeVanillaSwap childNative)  
{
	_pSpinlock = new boost::detail::spinlock ();
#ifdef HANDLE
	_phMakeVanillaSwap = NULL;
#endif
	_ppMakeVanillaSwap = new boost::shared_ptr<QuantLib::MakeVanillaSwap> (new QuantLib::MakeVanillaSwap (childNative));
    
}
#endif

Cephei::QL::Instruments::CMakeVanillaSwap::~CMakeVanillaSwap ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
        _pSpinlock = NULL;
    }
    if (_ppMakeVanillaSwap != NULL)
    {
	    delete _ppMakeVanillaSwap;
        _ppMakeVanillaSwap = NULL;
    }
}
Cephei::QL::Instruments::CMakeVanillaSwap::!CMakeVanillaSwap ()
{
	if (_pSpinlock != NULL)
    {
        delete _pSpinlock;
    }
    if (_ppMakeVanillaSwap != NULL)
    {
	    delete _ppMakeVanillaSwap;
    }
}
QuantLib::MakeVanillaSwap& Cephei::QL::Instruments::CMakeVanillaSwap::GetReference ()
{
    if (_ppMakeVanillaSwap == NULL) throw gcnew NativeNullException ();
	return **_ppMakeVanillaSwap;
}
boost::shared_ptr<QuantLib::MakeVanillaSwap>& Cephei::QL::Instruments::CMakeVanillaSwap::GetShared ()
{
    if (_ppMakeVanillaSwap == NULL) throw gcnew NativeNullException ();
	return *_ppMakeVanillaSwap;
}
QuantLib::MakeVanillaSwap* Cephei::QL::Instruments::CMakeVanillaSwap::GetPointer ()
{
    if (_ppMakeVanillaSwap == NULL) throw gcnew NativeNullException ();
	return &**_ppMakeVanillaSwap;
}
#ifdef HANDLE
QuantLib::Handle<QuantLib::MakeVanillaSwap>& Cephei::QL::Instruments::CMakeVanillaSwap::GetHandle ()
{
	if (_phMakeVanillaSwap == NULL)
	{
		_phMakeVanillaSwap = new Handle<QuantLib::MakeVanillaSwap> (*_ppMakeVanillaSwap);
	}
	return *_phMakeVanillaSwap;
}
#endif
bool Cephei::QL::Instruments::CMakeVanillaSwap::HasNative () 
{
	return (_ppMakeVanillaSwap != NULL);
}

Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::ReceiveFixed (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->receiveFixed ( _flag );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithDiscountingTermStructure (Cephei::QL::Termstructures::IYieldTermStructure^ discountingTermStructure)
{
    CYieldTermStructure^ _CdiscountingTermStructure;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _CdiscountingTermStructure = safe_cast<CYieldTermStructure^> (discountingTermStructure);
        _CdiscountingTermStructure->Lock();
        Handle<QuantLib::YieldTermStructure>& _discountingTermStructure = static_cast<Handle<QuantLib::YieldTermStructure>&> (_CdiscountingTermStructure->GetHandle ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withDiscountingTermStructure ( _discountingTermStructure );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_CdiscountingTermStructure != nullptr) _CdiscountingTermStructure->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithEffectiveDate (DateTime effectiveDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _effectiveDate = (QuantLib::Date)ValueHelper::Convert (effectiveDate);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withEffectiveDate ( _effectiveDate );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegCalendar (Cephei::QL::Times::ICalendar^ cal)
{
    CCalendar^ _Ccal;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ccal = safe_cast<CCalendar^> (cal);
        _Ccal->Lock();
        QuantLib::Calendar& _cal = static_cast<QuantLib::Calendar&> (_Ccal->GetReference ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegCalendar ( _cal );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccal != nullptr) _Ccal->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegDayCount (Cephei::QL::Times::IDayCounter^ dc)
{
    CDayCounter^ _Cdc;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cdc = safe_cast<CDayCounter^> (dc);
        _Cdc->Lock();
        QuantLib::DayCounter& _dc = static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegDayCount ( _dc );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegEndOfMonth ( _flag );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegFirstDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegFirstDate ( _d );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegNextToLastDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegNextToLastDate ( _d );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegRule (QL::Times::DateGeneration::RuleEnum r)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::DateGeneration::Rule _r = (QuantLib::DateGeneration::Rule)r ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegRule ( _r );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegTenor (Cephei::QL::Times::IPeriod^ t)
{
    CPeriod^ _Ct;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ct = safe_cast<CPeriod^> (t);
        _Ct->Lock();
        QuantLib::Period& _t = static_cast<QuantLib::Period&> (_Ct->GetReference ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegTenor ( _t );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ct != nullptr) _Ct->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFixedLegTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFixedLegTerminationDateConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegCalendar (Cephei::QL::Times::ICalendar^ cal)
{
    CCalendar^ _Ccal;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ccal = safe_cast<CCalendar^> (cal);
        _Ccal->Lock();
        QuantLib::Calendar& _cal = static_cast<QuantLib::Calendar&> (_Ccal->GetReference ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegCalendar ( _cal );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ccal != nullptr) _Ccal->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegDayCount (Cephei::QL::Times::IDayCounter^ dc)
{
    CDayCounter^ _Cdc;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Cdc = safe_cast<CDayCounter^> (dc);
        _Cdc->Lock();
        QuantLib::DayCounter& _dc = static_cast<QuantLib::DayCounter&> (_Cdc->GetReference ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegDayCount ( _dc );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Cdc != nullptr) _Cdc->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegEndOfMonth (Microsoft::FSharp::Core::FSharpOption<Boolean>^ flag)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        bool _flag = 
            (Microsoft::FSharp::Core::FSharpOption<Boolean>::IsSome::get (flag) ? (bool)ValueHelper::Convert (flag->Value) : true); //9a
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegEndOfMonth ( _flag );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegFirstDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegFirstDate ( _d );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegNextToLastDate (DateTime d)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _d = (QuantLib::Date)ValueHelper::Convert (d);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegNextToLastDate ( _d );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegRule (QL::Times::DateGeneration::RuleEnum r)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::DateGeneration::Rule _r = (QuantLib::DateGeneration::Rule)r ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegRule ( _r );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegSpread (Double sp)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Spread _sp = (QuantLib::Spread)ValueHelper::Convert (sp);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegSpread ( _sp );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegTenor (Cephei::QL::Times::IPeriod^ t)
{
    CPeriod^ _Ct;
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        _Ct = safe_cast<CPeriod^> (t);
        _Ct->Lock();
        QuantLib::Period& _t = static_cast<QuantLib::Period&> (_Ct->GetReference ()); 
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegTenor ( _t );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
        if (_Ct != nullptr) _Ct->Unlock();
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithFloatingLegTerminationDateConvention (QL::Times::BusinessDayConventionEnum bdc)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::BusinessDayConvention _bdc = (QuantLib::BusinessDayConvention)bdc ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withFloatingLegTerminationDateConvention ( _bdc );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithNominal (Double n)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Real _n = (QuantLib::Real)ValueHelper::Convert (n);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withNominal ( _n );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithRule (QL::Times::DateGeneration::RuleEnum r)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::DateGeneration::Rule _r = (QuantLib::DateGeneration::Rule)r ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withRule ( _r );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithTerminationDate (DateTime terminationDate)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::Date _terminationDate = (QuantLib::Date)ValueHelper::Convert (terminationDate);
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withTerminationDate ( _terminationDate );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap::WithType (QL::Instruments::VanillaSwap::TypeEnum type)
{
    try
    {
    	boost::detail::spinlock::scoped_lock lock (*_pSpinlock);
        QuantLib::VanillaSwap::Type _type = (QuantLib::VanillaSwap::Type)type ;
    	QuantLib::MakeVanillaSwap& _rv = (QuantLib::MakeVanillaSwap&)(*_ppMakeVanillaSwap)->withType ( _type );   
        Cephei::QL::Instruments::CMakeVanillaSwap^ _nrv = gcnew Cephei::QL::Instruments::CMakeVanillaSwap (_rv, this);
    	return _nrv;
	}
    catch (QuantLib::Error& _error)
    {
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown quantlib error"));
        
    }
	catch (std::exception& _error)
	{
        if (_error.what())
		    throw gcnew NativeExcpetion (gcnew System::String(_error.what()));
        else
		    throw gcnew NativeExcpetion (gcnew System::String("Unknown std::exception"));
	}
    finally
    {
    }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Factory class

Cephei::QL::Instruments::IMakeVanillaSwap^ Cephei::QL::Instruments::CMakeVanillaSwap_Factory::Create (Cephei::QL::Times::IPeriod^ swapTenor, Cephei::QL::Indexes::IIborIndex^ iborIndex, Microsoft::FSharp::Core::FSharpOption<Double>^ fixedRate, Microsoft::FSharp::Core::FSharpOption<Cephei::QL::Times::IPeriod^>^ forwardStart)
{
    return gcnew CMakeVanillaSwap ( swapTenor,  iborIndex,  fixedRate,  forwardStart);
}
